package bank.client;

import bank.bankieren.Money;
import java.io.FileInputStream;
import java.io.IOException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.util.Properties;

import bank.gui.GuiController;
import bank.internettoegang.IBalie;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.Serializable;
/**
 * 
 * @author Bart
 */
public class BankierApplicatie implements Serializable {

        private IBalie balie;
        private GuiController controller;
        private static BankierApplicatie applicatie;


	public BankierApplicatie(String bankNaam) throws RemoteException{
		try {
			FileInputStream in = new FileInputStream(bankNaam+".props");
			Properties props = new Properties();
			props.load(in);
			String rmiBalie = props.getProperty("balie");
			in.close();

			balie = (IBalie) Naming.lookup("rmi://" + rmiBalie);

			//controller = new GuiController(balie, bankNaam);
				
		} catch (Exception exc) {
			exc.printStackTrace();
		}

                //balie.addListener(this);

                controller = new GuiController(balie,bankNaam);
	}
	 /*
          * @TODO even uncommenten
          */
	public static void main(String[] args) throws RemoteException, IOException {
            System.out.print("Voer de banknaam in:");
            String naam = (new BufferedReader(new InputStreamReader(System.in))).readLine();
            System.out.println("Koppelen aan bank: " + naam + " ...");
		applicatie = new BankierApplicatie(naam);
	}

    public void update(int source, int destination) {
        if(controller.getRekening().getNr() == source || controller.getRekening().getNr() == destination)
        controller.getBankierDialoog().setBalance(controller.getRekening().getSaldo().toString());
    }
}
